package com.xjcs.saplingplan.datastore

import com.blankj.utilcode.util.GsonUtils
import com.xjcs.saplingplan.model.bean.focus.FocusTimer
import com.xjcs.saplingplan.model.bean.user.UserInfoBean

object AppData {

    //用户id
    fun getUserId(): String {
        return DataStoreUtils.readStringData(CacheUser.USER_ID, "")
    }

    fun setUserId(userId: String) {
        DataStoreUtils.saveSyncStringData(CacheUser.USER_ID, userId)
    }

    //用户信息
    fun getUserInfo(): UserInfoBean {
        val json = DataStoreUtils.readStringData(CacheUser.USER_INFO, "")
        return if (json.isEmpty()) {
            UserInfoBean()
        } else {
            GsonUtils.fromJson(json, UserInfoBean::class.java)
        }
    }

    fun setUserInfo(userInfo: UserInfoBean) {
        DataStoreUtils.saveSyncStringData(CacheUser.USER_INFO, GsonUtils.toJson(userInfo))
    }

    //专注数据
    fun getFocus(): FocusTimer {
        val json = DataStoreUtils.readStringData(CacheFocus.FOCUS_TIMER, "")
        return if (json.isEmpty()) {
            FocusTimer()
        } else {
            GsonUtils.fromJson(json, FocusTimer::class.java)
        }
    }

}